package com.example.matetest.slice.home;

import com.example.matetest.MainAbility;
import com.example.matetest.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class SetAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private static final String TAG = SetAbilitySlice.class.getSimpleName();
    private static final HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x00001, TAG);

    private Image imageBack;
    private Text title;

    private DirectionalLayout theme;
    private Switch switchTheme;

    private Button loginOut;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_set);

        title = (Text) findComponentById(ResourceTable.Id_tv_title);
        imageBack = (Image) findComponentById(ResourceTable.Id_iv_back);
        imageBack.setClickedListener(this);
        title.setText("设置");

        theme = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_theme);
        switchTheme = (Switch) findComponentById(ResourceTable.Id_st_switch_theme);
        //设置Switch默认状态
        switchTheme.setChecked(true);

        switchTheme.setCheckedStateChangedListener(new AbsButton.CheckedStateChangedListener() {
            // 回调处理Switch状态改变事件
            @Override
            public void onCheckedChanged(AbsButton button, boolean isChecked) {
                if (isChecked) {

                } else {

                }
            }
        });

        loginOut = (Button) findComponentById(ResourceTable.Id_btn_login_out);
        loginOut.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        if (component == imageBack) {
            terminate();
        }
        if (component == loginOut) {
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withAction("action.login")
                    .build();
            intent.setOperation(operation);
            startAbility(intent);
        }
    }


}